package com.ruoyi.customerSample.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.customerSample.domain.BackSampleDetail;
import com.ruoyi.customerSample.service.IBackSampleDetailService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 退样明细单据Controller
 * 
 * @author ruoyi
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/backSample/detail")
@Api(value="退样明细单据",tags = "退样明细单据")
public class BackSampleDetailController extends BaseController
{
    @Autowired
    private IBackSampleDetailService backSampleDetailService;

    /**
     * 查询退样明细单据列表
     */
    @PreAuthorize("@ss.hasPermi('backSample:detail:list')")
    @GetMapping("/list")
    @ApiOperation(value="查询退样明细单据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    public TableDataInfo list(BackSampleDetail backSampleDetail)
    {
        startPage();
        List<BackSampleDetail> list = backSampleDetailService.selectBackSampleDetailList(backSampleDetail);
        return getDataTable(list);
    }

    /**
     * 导出退样明细单据列表
     */
    @PreAuthorize("@ss.hasPermi('backSample:detail:export')")
    @Log(title = "退样明细单据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BackSampleDetail backSampleDetail)
    {
        List<BackSampleDetail> list = backSampleDetailService.selectBackSampleDetailList(backSampleDetail);
        ExcelUtil<BackSampleDetail> util = new ExcelUtil<BackSampleDetail>(BackSampleDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取退样明细单据详细信息
     */
    @PreAuthorize("@ss.hasPermi('backSample:detail:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取退样明细单据详细信息")
    @ApiImplicitParam(paramType="query", name = "id", value = "主键", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(backSampleDetailService.selectBackSampleDetailById(id));
    }

    /**
     * 新增退样明细单据
     */
    @PreAuthorize("@ss.hasPermi('backSample:detail:add')")
    @Log(title = "退样明细单据", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增退样明细单据")
    public AjaxResult add(@ApiParam(name="退样明细",value="传入json格式",required=true)@RequestBody BackSampleDetail backSampleDetail)
    {
        return toAjax(backSampleDetailService.insertBackSampleDetail(backSampleDetail));
    }

    /**
     * 修改退样明细单据
     */
    @PreAuthorize("@ss.hasPermi('backSample:detail:edit')")
    @Log(title = "退样明细单据", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改退样明细单据")
    public AjaxResult edit(@ApiParam(name="退样明细",value="传入json格式",required=true)@RequestBody BackSampleDetail backSampleDetail)
    {
        return toAjax(backSampleDetailService.updateBackSampleDetail(backSampleDetail));
    }

    /**
     * 删除退样明细单据
     */
    @PreAuthorize("@ss.hasPermi('backSample:detail:remove')")
    @Log(title = "退样明细单据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value="删除退样明细单据")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(backSampleDetailService.deleteBackSampleDetailByIds(ids));
    }
}
